package com.xbongbong.pro.rabbitmq.producer.impl;

import com.xbongbong.pro.product.pojo.dto.CostRecalculationDTO;
import com.xbongbong.pro.rabbitmq.binders.CostRecalculationProducerBinder;
import com.xbongbong.pro.rabbitmq.producer.CostRecalculationProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 成本重算生产者
 * @author jiping.yang
 * @date 2021/12/2 9:49
 */
@Service("costRecalculationProducer")
@EnableBinding(CostRecalculationProducerBinder.class)
public class CostRecalculationProducerImpl implements CostRecalculationProducer {

    private static final Logger LOG = LoggerFactory.getLogger(CostRecalculationProducerImpl.class);
    @Resource
    private CostRecalculationProducerBinder costRecalculationBinder;

    @Override
    public void sendMessage(CostRecalculationDTO costRecalculationDTO){
        try {
            LOG.info("发送消息为",costRecalculationDTO.toString());
            MessageBuilder messageBuilder = MessageBuilder.withPayload(costRecalculationDTO);
            costRecalculationBinder.costRecalculationOutput().send(messageBuilder.build());
        } catch (Exception e) {
            LOG.error("cost message fail：", e);
        }
    }

}
